import request from '@/utils/request'

// 班级圈相关API
export const classCircleApi = {
  // 创建班级圈（仅教师）
  createClassCircle(data) {
    return request({
      url: '/class-circle/create',
      method: 'post',
      data
    })
  },

  // 删除班级圈（仅创建者）
  deleteClassCircle(classCircleId) {
    return request({
      url: `/class-circle/${classCircleId}`,
      method: 'delete'
    })
  },

  // 搜索班级圈
  searchClassCircle(classId) {
    return request({
      url: '/class-circle/search',
      method: 'get',
      params: { classId }
    })
  },

  // 加入班级圈
  joinClassCircle(classCircleId) {
    return request({
      url: `/class-circle/${classCircleId}/join`,
      method: 'post'
    })
  },

  // 退出班级圈
  leaveClassCircle(classCircleId) {
    return request({
      url: `/class-circle/${classCircleId}/leave`,
      method: 'post'
    })
  },

  // 获取用户创建的班级圈
  getMyCreatedCircles() {
    return request({
      url: '/class-circle/my-created',
      method: 'get'
    })
  },

  // 获取用户加入的班级圈
  getMyJoinedCircles() {
    return request({
      url: '/class-circle/my-joined',
      method: 'get'
    })
  },

  // 获取班级圈成员
  getClassCircleMembers(classCircleId) {
    return request({
      url: `/class-circle/${classCircleId}/members`,
      method: 'get'
    })
  },

  // 检查用户是否已加入班级圈
  isUserJoined(classCircleId) {
    return request({
      url: `/class-circle/${classCircleId}/is-joined`,
      method: 'get'
    })
  },

  // 教师删除班级圈成员
  removeClassCircleMember(classCircleId, memberId) {
    return request({
      url: `/class-circle/${classCircleId}/members/${memberId}`,
      method: 'delete'
    })
  },

  // 获取所有班级圈（管理员）
  getAllClassCircles() {
    return request({
      url: '/class-circle/all',
      method: 'get'
    })
  }
}

// 兴趣社群相关API
export const interestCommunityApi = {
  // 创建兴趣社群
  createCommunity(data) {
    return request({
      url: '/interest-community/create',
      method: 'post',
      data
    })
  },

  // 删除兴趣社群
  deleteCommunity(communityId) {
    return request({
      url: `/interest-community/${communityId}`,
      method: 'delete'
    })
  },

  // 获取所有社群
  getAllCommunities() {
    return request({
      url: '/interest-community/all',
      method: 'get'
    })
  },

  // 根据分类获取社群
  getCommunitiesByCategory(category) {
    return request({
      url: `/interest-community/category/${category}`,
      method: 'get'
    })
  },

  // 加入社群
  joinCommunity(communityId) {
    return request({
      url: `/interest-community/${communityId}/join`,
      method: 'post'
    })
  },

  // 退出社群
  leaveCommunity(communityId) {
    return request({
      url: `/interest-community/${communityId}/leave`,
      method: 'post'
    })
  },

  // 获取用户创建的社群
  getMyCreatedCommunities() {
    return request({
      url: '/interest-community/my-created',
      method: 'get'
    })
  },

  // 获取用户加入的社群
  getMyJoinedCommunities() {
    return request({
      url: '/interest-community/my-joined',
      method: 'get'
    })
  },

  // 获取社群成员
  getCommunityMembers(communityId) {
    return request({
      url: `/interest-community/${communityId}/members`,
      method: 'get'
    })
  },

  // 检查用户是否已加入社群
  isUserJoined(communityId) {
    return request({
      url: `/interest-community/${communityId}/is-joined`,
      method: 'get'
    })
  },
  // 移除兴趣社群成员
  removeCommunityMember(communityId, userId) {
    return request({
      url: `/interest-community/${communityId}/member/${userId}`,
      method: 'delete'
    })
  }
}

// 社群帖子相关API
export const communityPostApi = {
  // 发布帖子
  createPost(data) {
    return request({
      url: '/community-post/create',
      method: 'post',
      data
    })
  },

  // 删除帖子
  deletePost(postId) {
    return request({
      url: `/community-post/${postId}`,
      method: 'delete'
    })
  },

  // 获取社群的所有帖子
  getCommunityPosts(communityId) {
    return request({
      url: `/community-post/community/${communityId}`,
      method: 'get'
    })
  },

  // 获取帖子详情
  getPostDetail(postId) {
    return request({
      url: `/community-post/${postId}`,
      method: 'get'
    })
  },

  // 点赞/取消点赞帖子
  togglePostLike(postId) {
    return request({
      url: `/community-post/${postId}/like`,
      method: 'post'
    })
  },

  // 发布评论
  createComment(data) {
    return request({
      url: '/community-post/comment',
      method: 'post',
      data
    })
  },

  // 删除评论
  deleteComment(commentId) {
    return request({
      url: `/community-post/comment/${commentId}`,
      method: 'delete'
    })
  },

  // 获取帖子的所有评论
  getPostComments(postId) {
    return request({
      url: `/community-post/${postId}/comments`,
      method: 'get'
    })
  },

  // 点赞/取消点赞评论
  toggleCommentLike(commentId) {
    return request({
      url: `/community-post/comment/${commentId}/like`,
      method: 'post'
    })
  },


} 